package offer;

public class offer_0018 {
    public ListNode deleteNode(ListNode head, int val) {
        if(head==null) return head;
        if(head.val==val) return head.next;
        ListNode p=head;
        ListNode q=head.next;
        while(q!=null){
            if(q.val==val){
                p.next=q.next;
                return head;
            }
            p=p.next;
            q=q.next;
        }
        return head;
    }
}
